package com.gsit.expenditure.client.domina;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import com.gsit.expenditure.domain.Customer;
import com.gsit.expenditure.domain.CustomerAddress;

public class CustomerBean implements BeanHendler<Customer> {

	private StringProperty firstName = new SimpleStringProperty("");

	private StringProperty lastName = new SimpleStringProperty("");

	private StringProperty email = new SimpleStringProperty("");

	private StringProperty phone = new SimpleStringProperty("");

	private StringProperty mobile = new SimpleStringProperty("");

	private StringProperty address1 = new SimpleStringProperty("");

	private StringProperty address2 = new SimpleStringProperty("");

	private StringProperty city = new SimpleStringProperty("");

	private StringProperty state = new SimpleStringProperty("");

	private StringProperty country = new SimpleStringProperty("");

	private StringProperty pinCode = new SimpleStringProperty();
	

	private Customer customer;

	

	public CustomerBean(Customer customer) {
		if (customer == null) {
			customer = new Customer();

		}
		this.customer = customer;
		// init(customer);
	}

	@Override
	public void init(Customer customer) {
		if (customer != null) {
			firstName.setValue(customer.getFirstName());
			lastName.setValue(customer.getLastName());
			email.setValue(customer.getEmail());
			phone.setValue(customer.getPhone());
			mobile.setValue(customer.getMobile());
			if(customer.getAddress() != null){
				address1.setValue(customer.getAddress().getAddress1());
				address2.setValue(customer.getAddress().getAddress2());
				city.setValue(customer.getAddress().getCity());
				state.setValue(customer.getAddress().getState());
				country.setValue(customer.getAddress().getCountry());
				pinCode.setValue(customer.getAddress().getPinCode());
			}
			
		}
	}

	@Override
	public void reLoad(Customer customer) {
		this.customer = customer;
		init(customer);
	}

	@Override
	public void clean() {
		firstName.setValue("");
		lastName.setValue("");
		email.setValue("");
		address1.setValue("");
		address2.setValue("");
		city.setValue("");
		state.setValue("");
		country.setValue("");
		pinCode.setValue("");
		phone.set("");
		mobile.set("");

	}

	@Override
	public Customer getObject() {
		if(this.customer == null){
			this.customer = new Customer();
		}
		this.customer.setFirstName(firstName.getValue());
		this.customer.setLastName(lastName.getValue());
		this.customer.setEmail(email.getValue());
		this.customer.setPhone(phone.getValue());
		this.customer.setMobile(mobile.getValue());

		CustomerAddress customerAddress = new CustomerAddress();
		customerAddress.setAddress1(address1.getValue());
		customerAddress.setAddress2(address2.getValue());
		customerAddress.setCity(city.getValue());
		customerAddress.setState(state.getValue());
		customerAddress.setCountry(country.getValue());
		customerAddress.setPinCode(pinCode.getValue());
		this.customer.setAddress(customerAddress);

		return this.customer;
	}

	
	public StringProperty getFirstName() {
		return firstName;
	}

	public void setFirstName(StringProperty firstName) {
		this.firstName = firstName;
	}

	public StringProperty getLastName() {
		return lastName;
	}

	public void setLastName(StringProperty lastName) {
		this.lastName = lastName;
	}

	public StringProperty getEmail() {
		return email;
	}

	public void setEmail(StringProperty email) {
		this.email = email;
	}

	public StringProperty getPhone() {
		return phone;
	}

	public void setPhone(StringProperty phone) {
		this.phone = phone;
	}

	public StringProperty getMobile() {
		return mobile;
	}

	public void setMobile(StringProperty mobile) {
		this.mobile = mobile;
	}

	public StringProperty getAddress1() {
		return address1;
	}

	public void setAddress1(StringProperty address1) {
		this.address1 = address1;
	}

	public StringProperty getAddress2() {
		return address2;
	}

	public void setAddress2(StringProperty address2) {
		this.address2 = address2;
	}

	public StringProperty getCity() {
		return city;
	}

	public void setCity(StringProperty city) {
		this.city = city;
	}

	public StringProperty getState() {
		return state;
	}

	public void setState(StringProperty state) {
		this.state = state;
	}

	public StringProperty getCountry() {
		return country;
	}

	public void setCountry(StringProperty country) {
		this.country = country;
	}

	public StringProperty getPinCode() {
		return pinCode;
	}

	public void setPinCode(StringProperty pinCode) {
		this.pinCode = pinCode;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	@Override
	public String toString() {
		return "CustomerBean [firstName=" + firstName + ", lastName="
				+ lastName + ", email=" + email + ", phone=" + phone
				+ ", mobile=" + mobile + ", address1=" + address1
				+ ", address2=" + address2 + ", city=" + city + ", state="
				+ state + ", country=" + country + ", pinCode=" + pinCode
				+ ", customer=" + customer + "]";
	}

}
